<?php
if (!defined('CURRENT_PATH')){
	die('Hacking attempt');
	}
if($_REQUEST['act']&&$_REQUEST['act']=='add'){
		$this->display('management/friendlinkadd.html');	
}else if($_REQUEST['act']&&$_REQUEST['id']&&$_REQUEST['act']=='modify'){
		$fl=spClass(friend_link);
		$id=intval($_REQUEST['id']);
		$res=$fl->find($conditions=array('link_id'=>$id));
		//dump($res);
		$this->res=$res;
		$this->display('management/friendlinkmodify.html');	
}else if($_REQUEST['act']&&$_REQUEST['id']&&$_REQUEST['act']=='del'){
		$fl=spClass(friend_link);
		echo $id=intval($_REQUEST['id']);
		$res=$fl->delete($conditions=array('link_id'=>$id));
		$this->success("恭喜，操作成功！");
}else if($_REQUEST['act']&&$_REQUEST['act']=='save'){
		$input=$this->spArgs();
		//dump($input);
		$input[showOrder]=intval($input[showOrder]);
		if(!empty($input[linkName])&&!empty($input[linkUrl])){
			$fl=spClass(friend_link);
			$saveMapArr=array('linkName'=>'link_name','linkUrl'=>'link_url',/*'imageurl'=>'link_logo',*/'showOrder'=>'show_order',);
			$newrow=array();
			foreach($saveMapArr as $id=>$v){
				$tempArr=array($v=>$input[$id]);
				$newrow=array_merge($newrow,$tempArr);
			}
//此处判断新增还是更新
		if($_REQUEST['id']){
				$id=intval($_REQUEST['id']);
				$fl->update($conditions=array('link_id'=>$id),$newrow);
				$msg='恭喜！修改友情链接成功！';
			}else{
				$fl->create($newrow);
				$msg='恭喜！新增友情链接成功！';			
			}			
		$this->success($msg);
		//dump($newrow);	
		}else{
		$this->error('您的输入有误！请填写完整后再提交！');
		}			
}else{
		 $fl=spClass(friend_link);
		 $res=$fl->findAll($conditions = null,$sort ='show_order desc');
		 $this->res=$res;
		 $this->display('management/friendlink.html');
}	
	
	//